package com.zhy_9.maidu;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.youth.xframe.base.XActivity;
import com.youth.xframe.utils.http.HttpCallBack;
import com.youth.xframe.utils.http.XHttp;
import com.zhy_9.maidu.adapter.HomeAdapter;
import com.zhy_9.maidu.model.HomeBean;
import com.zhy_9.maidu.model.HomeData;

import java.util.List;


public class MainActivity extends XActivity {

    private RecyclerView goodsList;
    List<HomeBean.News> data;
    HomeAdapter adapter;

    @Override
    public int getLayoutId() {
        return R.layout.activity_main;
    }

    @Override
    public void initData(Bundle savedInstanceState) {
        XHttp.obtain().post("http://172.16.60.85/shopapi/index.php/first/index", null, new HttpCallBack<HomeData>() {


            @Override
            public void onSuccess(HomeData homeData) {
                data = homeData.getData().getNews();
                adapter = new HomeAdapter(data, MainActivity.this);
                goodsList.setAdapter(adapter);
            }

            @Override
            public void onFailed(String error) {

            }
        });
    }

    @Override
    public void initView() {
        goodsList = (RecyclerView) findViewById(R.id.goods_list);
        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        goodsList.setLayoutManager(layoutManager);

    }
}
